<?php
   /**
    * CHILD FILE OF TOWN.PHP
    * */
   
   $c = getCharacterRecord($_SESSION['id']);
       
   hr($settings['game']['bank_name'],'1');
   echo '<p>';
   
   
   
   if(isset($_SESSION['msg']) && $_SESSION['msg'] > '')
   {
        $msg = $_SESSION['msg'];
        lwriteln($msg);
        $_SESSION['msg'] = '';
   }
   else
   {
        lwriteln('`2'.$settings['locationIntro']['bank'].' ',false);
        $settings['gossip']['bank_teller'] =
            str_ireplace('%s',$c['sex'] > 0?'lil miss':'kind sir',
                         $settings['gossip']['bank_teller']
                         );
        lwriteln('`5"'.$settings['gossip']['bank_teller'].'"');
   }
   
?>
<script src="scripts/hotkeys.js" type="text/javascript"></script>
<script type="text/javascript">
	shortcut.add("d",function() {window.location.assign("?loc=b&trans=d");});
	shortcut.add("w",function() {window.location.assign("?loc=b&trans=w");});
	shortcut.add("t",function() {window.location.assign("?loc=b&trans=t");});
	shortcut.add("r",function() {window.location.assign("town.php");});
    
</script>
<p>
    <table>
        <tr>
            <td><a href="?loc=b&trans=d"><?=lwriteln('`0(`5D`0)`2eposit Money',false);?></a></td>
        </tr>
        <tr>
            <td><a href="?loc=b&trans=w"><?=lwriteln('`0(`5W`0)`2ithdraw Money',false);?></a></td>
        </tr>
        <tr>
            <td><a href="?loc=b&trans=t"><?=lwriteln('`0(`5T`0)`2ransfer Money',false);?></a></td>
        </tr>
        <tr>
            <td><a href="town.php"><?=lwriteln('`0(`5R`0)`2eturn to town');?></a></td>
        </tr>        
    </table>
</p>
<p>
    <?=lwriteln('`2Gold on hand: `0'.$c['gold'],false);?>
    <?=lwriteln('`2Gold in bank: `0'.$c['goldInBank']);?>
    <?=lwriteln('`5'.$settings['game']['bank_name'].'`8(d,w,t,r)');?>
</p>
<p>
    <?=lwriteln('`2Your choice `0'.$c['name'].': ',false);?>
</p>
<?php
    /* check for bank transaction  and show results */
    if(isset($_GET['trans']))
    {
        /** do they have money to work with */
        if($c['gold'] <= 0 && ($_GET['trans'] == 'd' || $_GET['trans'] == 't'))
        {
            lwriteln('`4"HEY! Waddaya tryin to pull! Come back when you have some gold.');
        }
        elseif($c['goldInBank'] <= 0 && $_GET['trans'] == 'w')
        {
            lwriteln('`4"We don\'t do loans here! Come back when you have some gold.');    
        }
        else
        {
            
            switch($_GET['trans'])
            {
                case 'd' :
                    echo '<form method="post" action="?loc=b&trans=d">';
                    echo '<input type="number" name="amt" placeholder="Enter Deposit"/> ';
                    echo '<input type="submit" name="process" value="Process"/>';
                    echo '</form>';
                    break;
                
                case 'w' :
                    echo '<form method="post" action="?loc=b&trans=w">';
                    echo '<input type="number" name="amt" placeholder="Enter Withdraw"/> ';
                    echo '<input type="submit" name="process" value="Process"/>';
                    echo '</form>';
                    break;
                
                case 't' :
                    echo '<form method="post" action="?loc=b&trans=t">';
                    echo '<input type="number" name="amt" placeholder="Enter Deposit"/> ';
                    echo '<input type="submit" name="process" value="Process"/>';
                    echo '</form>';
                    break;
            
            }
        }// money check
    }// trans check
    
    // MAKING A TRANSACTION
    if(isset($_POST['amt']))
    {
        $amount = $_POST['amt'];
        switch($_GET['trans'])
        {
            case 'd' :                
                if($amount > $c['gold']) $amount = $c['gold'];
                update($_SESSION['id'],'goldInBank',($c['goldInBank'] + $amount));
                update($_SESSION['id'],'gold',($c['gold'] - $amount));
                $_SESSION['msg'] = '`2Banker takes your `$'.$amount.'`2gp and quickly stashes it in a nearby safe.';
                header('location:?loc=b');
                break;
            
            case 'w' :                
                if($amount > $c['goldInBank']) $amount = $c['goldInBank'];
                update($_SESSION['id'],'gold',($c['gold'] + $amount));
                update($_SESSION['id'],'goldInBank',($c['goldInBank'] - $amount));
                $_SESSION['msg'] = '`2Banker sourly, hands over `$'.$amount.'`2gp. `5"..Good luck with that!"';
                header('location:?loc=b');
                break;
            
        }
    }
?>
    
